//
//  ComposeViewController.swift
//  SinaWeiBo
//
//  Created by 有风 on 16/2/3.
//  Copyright © 2016年 YouFeng. All rights reserved.
//

import UIKit
import SnapKit

class ComposeViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = UIColor.whiteColor()
        setNavBar()
        setTextView()
    }

    //MARK: 设置导航条
    private func setNavBar() {

        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "关闭", style: .Plain, target: self, action: "close")
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "发布", style: .Plain, target: self, action: "broadcast")
        
        self.navigationItem.rightBarButtonItem?.enabled = false
        
        let titleLabel = UILabel(text: "发布微博", fontSize: 18, textColor: UIColor.blackColor())
        let nameLabel = UILabel(text: AccountViewModel.sharedAccountViewModel.userName ?? "", fontSize: 15, textColor: UIColor.darkGrayColor())
        let titleView = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 40))
        
        navigationItem.titleView = titleView
        
        titleView.addSubview(titleLabel)
        titleView.addSubview(nameLabel)
        
        titleLabel.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(titleView.snp_centerX)
            make.top.equalTo(titleView.snp_top)
            
        }

        nameLabel.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(titleView.snp_centerX)
            make.top.equalTo(titleLabel.snp_bottom)
        }
        
    }

    @objc private func close() {
        dismissViewControllerAnimated(true) { () -> Void in }
        
    }
    
    //MARK: 发布微博
    @objc private func broadcast() {
        
    }
    
    //MARK: 设置textView
    private func setTextView() {
        self.view.addSubview(textFiled)
        
        textFiled.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.view.snp_top)
            make.left.equalTo(self.view.snp_left)
            make.right.equalTo(self.view.snp_right)
            make.height.equalTo(300)
        }
    }
    private lazy var textFiled: UITextView = {
        let tv = UITextView()
        
        tv.textColor = UIColor.blackColor()
        tv.backgroundColor = UIColor.lightGrayColor()
        tv.font = UIFont.systemFontOfSize(15)
        tv.keyboardDismissMode = .OnDrag
        
        //tv.delegate = self
        
        return tv
    }()
}
